import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/view/appraisal.dart';
import 'package:flutter_app/view/community.dart';
import 'package:flutter_app/view/message.dart';
import 'package:flutter_app/view/mini.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Tabs extends StatefulWidget {
  @override
  _TabsState createState() => _TabsState();
}

class _TabsState extends State<Tabs> {
  int _currentIndex = 0;

  List<Widget> _pageList = [Community(), Appraisal(), Message(), Mine()];
  PageController _controller;

  @override
  void initState() {
    _controller = PageController(initialPage: _currentIndex);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 375, height: 667);
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: _pageList,
        physics: NeverScrollableScrollPhysics(),
        onPageChanged: (index) {
          _currentIndex = index;
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          onTap: (index) {
            setState(() {
              _controller.jumpToPage(index);
            });
          },
          type: BottomNavigationBarType.fixed,
          //多个菜单显示需要配置此属性
          fixedColor: Colors.red,
          //选中的颜色
          items: [
            BottomNavigationBarItem(icon: Icon(Icons.home), title: Text("社区")),
            BottomNavigationBarItem(
                icon: Icon(Icons.category), title: Text("测评")),
            BottomNavigationBarItem(
                icon: Icon(Icons.shopping_cart), title: Text("消息")),
            BottomNavigationBarItem(
                icon: Icon(Icons.people), title: Text("我的")),
          ]),
    );
  }
}
